Description | : > [!NOTE] > > **Azure Maps Spatial service retirement** > > The Azure Maps Spatial service is now deprecated and will be retired on 9/30/25. For more information, see [End of Life Announcement of Azure Maps Spatial](https://aka.ms/AzureMapsSpatialDeprecation). The `Get Geofence` API is an HTTP `GET` request that retrieves the proximity of a coordinate to a geofence that has been uploaded to the Data registry. You upload a geofence or set of fences into an Azure Storage Account, then register it with your Azure Maps Account using the [Data registry](/rest/api/maps/data-registry/register-or-replace), for more information see [How to create data registry](/azure/azure-maps/how-to-create-data-registries). For more information on on the geofence data format, see [Geofencing GeoJSON data](/azure/azure-maps/geofence-geojson). To query the proximity of a coordinate, you supply the location of the object you are tracking as well as the ID for the fence or set of fences, and the response will contain information about the distance from the outer edge of the geofence. A negative value signifies that the coordinate is inside of the fence while a positive value means that it is outside of the fence. This API can be used for a variety of scenarios that include things like asset tracking, fleet management, or setting up alerts for moving objects. The API supports [integration with Event Grid](/azure/azure-maps/azure-maps-event-grid-integration). The isAsync parameter is used to enable integration with Event Grid (disabled by default). To test this API, you can upload the sample data from Post Geofence API examples (Request Body) using the Data registry service and replace the `{udid}` from the sample request below with the `udid` used to create the Data registry. For more information on the data registry service, see [How to create data registry](/azure/azure-maps/how-to-create-data-registries). ### Geofencing InnerError code In geofencing response error contract, `innererror` is an object containing service specific information about the error. `code` is a property in `innererror` which can map to a specific geofencing error type. The table belows shows the code mapping between all the known client error type to the corresponding geofencing error `message`. innererror.code | error.message ---------------------------- | -------------------------------------- NullDeviceId | Device Id should not be null. NullUdid | Udid should not be null. UdidWrongFormat| Udid should be acquired from user data ingestion API. InvalidUserTime| Usertime is invalid. InvalidSearchBuffer| Searchbuffer is invalid. InvalidSearchRange| The value range of searchbuffer should be from 0 to 500 meters. InvalidLatLon| Lat and/or lon parameters are invalid. InvalidIsAsyncValue| The IsAsync parameter is invalid. InvalidModeValue| The mode parameter invalid. InvalidJson| Geofencing data is not a valid json file. NotSupportedGeoJson| Geofencing data can't be read as a Feature or FeatureCollections. InvalidGeoJson| Geofencing data is invalid. NoUserDataWithAccountOrSubscription| Can't find user geofencing data with provided account-id and/or subscription-id. NoUserDataWithUdid| Can't find user geofencing data with provided udid. |
Reference | : Link ¶ |
⚼ Request
GET:
/spatial/geofence/{format}
{
x-ms-client-id:
string
,
api-version:
string
,
format:
string
,
deviceId:
string
,
udid:
string
,
lat:
number
,
lon:
number
,
z:
number
,
userTime:
string
,
searchBuffer:
number
,
isAsync:
boolean
,
mode:
string
,
}
⚐ Response (200)
{
$headers:
{
,
x-correlation-id:
string
,
}
$schema:
}
{
,
geometries:
[
]
,
{
,
deviceId:
string
,
udId:
string
,
geometryId:
string
,
distance:
number
,
nearestLat:
number
,
nearestLon:
number
,
nearestZ:
number
,
}
expiredGeofenceGeometryId:
[
,
string
,
]
invalidPeriodGeofenceGeometryId:
[
,
string
,
]
isEventPublished:
boolean
,
}
⚐ Response (default)
{
error:
}
{
,
code:
string
,
message:
string
,
target:
string
,
details:
[
,
string
,
]
additionalInfo:
}
[
]
,
{
,
type:
string
,
info:
object
,
}